<template>
  <a-modal
    class="fillmaskModal"
    title="从模板库里添加"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top: 5%; height: 85%; overflow-y: hidden"
  >
  
    <a-row>
  <a-col :md="24" :sm="24" class="collect_tab">
        <a-card :bordered="false">
          <!-- 查询区域 -->

          <!-- 操作按钮区域 -->

          <div style="margin-top: 15px">
            <a-table
              style="height: 500px"
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="columns"
              :dataSource="dataSource1"
              :pagination="ipagination"
              :loading="loading"
              :rowSelection="{
                selectedRowKeys: selectedRowKeys1,
                onChange: onSelectChange1,
              }"
              @change="handleTableChange"
            >
              <span slot="action" slot-scope="text, record">
                <a>编辑</a>
                <a-divider type="vertical" />
                <a>删除</a>
              </span>
            </a-table>
          </div>
        </a-card>
      </a-col>
    </a-row>

  </a-modal>
</template>

<script>
import { addRole, editRole, duplicateCheck } from "@/api/api";
import { ListMixin } from "@/mixins/ListMixin";
export default {
      mixins: [ListMixin],
  name: "RoleModal",
  data() {
    return {
      title: "操作",
      visible: false,
      roleDisabled: false,
      model: {
        template: "",
        standard: "",
      },

        dataSource1: [
        {
          taskName: "我的模板",
          date: "标准对标国标",
          createBy: "admin",
          state: "	2023-02-10 11:06:48",
          update: "2022-01-06",
          total: 1340,
        },
        {
          taskName: "发改委标准",
          date: "发改委标准",
          createBy: "admin",
          state: "2023-02-10 11:06:48",
          update: "2022-01-06",
          total: 1340,
        },
      ],
          columns: [
        {
          title: "模板名称",
          align: "left",
          dataIndex: "taskName",
        },

        {
          title: "对标标准",
          align: "left",
          dataIndex: "date",
        },
        {
          title: "修改人 ",
          align: "left",
          dataIndex: "createBy",
        },
        {
          title: "更新时间",
          align: "left",
          dataIndex: "state",
        },

        {
          title: "操作",
          dataIndex: "action",
          align: "left",
          scopedSlots: { customRender: "action" },
        },
      ],
      layout: {
        labelCol: { span: 3 },
        wrapperCol: { span: 14 },
      },
      confirmLoading: false,
 
    };
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    onSelectChange1(){},
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
      //编辑页面禁止修改角色编码
      if (this.model.id) {
        this.roleDisabled = true;
      } else {
        this.roleDisabled = false;
      }
    },
    close() {
      //   this.$refs.form.clearValidate();
      this.$emit("close");
      this.visible = false;
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true;
          let obj;
          if (!this.model.id) {
            obj = addRole(this.model);
          } else {
            obj = editRole(this.model);
          }
          obj
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit("ok");
              } else {
                that.$message.warning(res.message);
              }
            })
            .finally(() => {
              that.confirmLoading = false;
              that.close();
            });
        } else {
          return false;
        }
      });
    },
    handleCancel() {
      this.close();
    },
    validateRoleCode(rule, value, callback) {
      if (/[\u4E00-\u9FA5]/g.test(value)) {
        callback("角色编码不可输入汉字!");
      } else {
        let params = {
          tableName: "sys_role",
          fieldName: "role_code",
          fieldVal: value,
          dataId: this.model.id,
        };
        duplicateCheck(params).then((res) => {
          if (res.success) {
            callback();
          } else {
            callback(res.message);
          }
        });
      }
    },
  },
};
</script>

<style lang="scss" >
@import "@/assets/css/newrModule.scss";
.fillmaskModal .ant-modal-body {
  padding-top: 0px !important;
  padding-left: 0;
  padding-right: 0;
}
.fillmaskModal .ant-spin-nested-loading {
  padding: 12px 24px !important;
}
.fillmaskModal .ant-select-selection-selected-value {
  font-size: 12px;
}
.fillmaskModal .info {
  background: #ebf5fe;

  background-image: linear-gradient(
    rgb(209, 231, 253),
    rgba(245, 249, 253, 0.644)
  );
  padding: 12px 24px !important;
  margin-bottom: 10px;
  //   border-bottom: 1px dashed rgb(241, 241, 241);
  p {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    margin-bottom: 4px;
  }
}
</style>